from datetime import datetime as dt
import yfinance as yf
import pandas as pd
#import matplotlib.pyplot as plt
import pytz

symbol = "NVDA"  
start_date = "2023-01-01"
end_date = "2024-08-11"
tz = pytz.timezone("Asia/Shanghai")
start_date = tz.localize(dt(2024,8,22))
end_date= tz.localize(dt(2024,8,22))
data = yf.download(symbol, start_date, end_date)

data['SMA_50'] = data['Close'].rolling(window=5).mean()
data['SMA_200'] = data['Close'].rolling(window=10).mean()

data['Signal'] = 0

data.loc[data['SMA_50'] > data['SMA_200'], 'Signal'] = 1
data.loc[data['SMA_50'] < data['SMA_200'], 'Signal'] = -1

data['Daily_Return'] = data['Close'].pct_change()

data['Strategy_Return'] = data['Signal'].shift(1) * data['Daily_Return']

data['Cumulative_Return'] = (1 + data['Strategy_Return']).cumprod()

print(data.head(1000000))
